<?php

/**
 * remarks actions.
 *
 * @package    sf_sandbox
 * @subpackage remarks
 * @author     Your name here
 * @version    SVN: $Id: actions.class.php 2288 2006-10-02 15:22:13Z fabien $
 */
class remarksActions extends autoremarksActions
{

    public function executeComment()
    {

    }

    public function executeSaveComment()
    {
		
        $remark = new Remarks();
        $remark->setStatusId(MyConstants::OBJ_STATUS_ACTIVE);
        $remark->setUserId(MyConstants::UNDEFINED_ID);
        $remark->setRating('10');
        $remark->setObjType(MyConstants::TYPE_NEWS);
        $remark->setObjId($this->getRequestParameter('objId'));
        $remark->setText($this->getRequestParameter('text'));
        $remark->setUserName($this->getRequestParameter('userName'));
        $remark->setUserSurname($this->getRequestParameter('userSurname'));
        $remark->setUserEmail($this->getRequestParameter('userEmail'));
        $remark->save();

        //debugvar($remark);
        //die();
		$this->setFlash('success', 'remark saved');
        $this->redirect('news/view?id=' . $this->getRequestParameter('objId'));
    }

    public function validateSaveComment()
    {
		/*
		include_once $_SERVER['DOCUMENT_ROOT'] . '/captcha/securimage.php';
		$securimage = new Securimage();
		if ($securimage->check($this->getRequestParameter('captcha_code')) == false)
		{
			// the code was incorrect
			// handle the error accordingly with your other error checking

			// or you can do something really basic like this
			die('The code you entered was incorrect.  Go back and try again.');
		} else
		*/
		$isOk = true;
		if( !$this->getRequestParameter('text') ) 
		{
		    $this->getRequest()->setError('text', 'text field is empty');
			$isOk = false;
		}
		if( !$this->getRequestParameter('userName') ) 
		{
		    $this->getRequest()->setError('userName', 'name field is empty');
		}
		if( $isOk == true ) 
		{
		    $this->getUser()->getAttributeHolder()->remove('userName');
		}
		return $isOk;
    }

	public function handleErrorSaveComment() 
	{
		$this->getUser()->setAttribute('userName', $this->getRequestParameter('userName'));

		$this->redirect('news/view?id=' . $this->getRequestParameter('objId'));
	}

    public function executeConfirm()
    {

    }

}
